<!-- 研发型体查询：蹇泽阳 -->
<template>
  <div class="app-container">
    <div class="ProductionDynamicHeader">
      <Find :OriginalFilter="{ static: true }" :formList="formList" @findClicked="findClicked" />
    </div>

    <!-- 左侧 -->
    <div class="Main mt10">
      <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
        <div class="flex AIC">
          <h1 class="f16">型体</h1>
          <span class="ml10" style="font-size: 12px; color: #0000ff">填充绿色为已审核</span>
        </div>
        <Table
          selection
          :tableData="tableData"
          :tableHeader="tableHeader"
          :TableHeight="50"
          :outTableHeight="170"
          @currentRow="currentRow"
          @selectList="selectTableList"
        />
      </el-card>

      <!-- 右侧 -->
      <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
        <div slot="header" class="f16 mb9">
          <span style="font-weight: 600">制具资料</span>
        </div>
        <Table :isLoading="isLoading2" :tableData="tableData2" :tableHeader="tableHeader2" :TableHeight="20" :outTableHeight="170" />
      </el-card>
      <div class="flex">
        <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
          <div slot="header" class="f16 mb9">
            <span style="font-weight: 600">配码资料</span>
          </div>
          <Table :isLoading="isLoading2" :tableData="tableData3" :tableHeader="tableHeader3" :TableHeight="30" :outTableHeight="170" />
        </el-card>
        <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
          <div slot="header" class="f16 mb9">
            <span style="font-weight: 600">型体配色资料</span>
          </div>
          <Table :isLoading="isLoading2" :tableData="tableData4" :tableHeader="tableHeader4" :TableHeight="30" :outTableHeight="170" />
        </el-card>
      </div>
      <el-card shadow="never" :body-style="{ padding: '10px' }">
        <PageModule :PageData="{ total }" style="background-color: white" @pageSizeChange="handleSizeChange" @pageChange="handleCurrentChange" />
      </el-card>
    </div>
  </div>
</template>
<script lang="ts">
import fileRequest from '@/utils/fileRequest'
import service from '@/utils/request'
import { ElMessage } from 'element-plus'
import { debounce } from 'lodash'
import { defineComponent, onMounted, ref, watch } from 'vue'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'ResearchType'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
// 表一模块
const formList = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入型体',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '制单员',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '请输入鞋名',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '季度',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '请输入冲刀',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '客户',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '请输入客户型体',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '导出'
  }
])
const selectedLists = ref([]) as any
const selectTableList = (selectedList: any) => {
  selectedLists.value = selectedList
}
// '置空'按钮
const findClicked = async (content: string) => {
  if (content === '置空') {
    formList.value.forEach((item) => {
      item.inputValue = ''
      item.selectValue = ''
    })
  }
  if (content === '导出') {
    if (selectedLists.value.length === 0) {
      JMessage.warning('请勾选型体')
      return
    }
    const res = (await fileRequest.post(
      `/quotation/downloadStyle`,
      selectedLists.value.map((item: any) => item.styleNo)
    )) as any
    const link = document.createElement('a') // 利用a标签自定义下载文件名
    let blob = new Blob([res.data]) // 创建Blob对象，设置文件类型
    link.style.display = 'none'
    //设置连接
    link.href = window.URL.createObjectURL(blob)
    link.download = `研发型体查询导出${Date.now()}.xls` //自定义文件名字
    document.body.appendChild(link)
    //模拟点击事件
    link.click()
    document.body.removeChild(link)
  }
  getTableList()
}
const tableData = ref([])
const tableHeader = ref([
  {
    cfmFlag: '#40ff80',
    label: '型体',
    prop: 'styleNo'
  },
  {
    label: '制单员',
    prop: 'techPerson'
  },
  {
    label: '鞋名',
    prop: 'styleName'
  },
  {
    label: '码制',
    prop: 'sizeType'
  },
  {
    label: '基本号(鞋号)',
    prop: 'baseSize'
  },
  {
    label: '基本号(冲刀)',
    prop: 'baseCutSize'
  },
  {
    label: '材质类别',
    prop: 'customNo'
  },
  {
    label: '客户',
    prop: 'custNo'
  },
  {
    width: '120px',
    label: '客户型体',
    prop: 'custStyle'
  },
  {
    label: '季度',
    prop: 'season'
  },
  {
    label: '鞋款分类',
    prop: 'shoeType'
  },
  {
    label: '鞋款性别',
    prop: 'shoeSex'
  },
  {
    label: '成型做法',
    prop: 'lastMethod'
  },
  {
    label: '商标',
    prop: 'custBrand'
  },
  {
    label: '原客户型体',
    prop: 'prevCustStyle'
  },
  {
    label: '大底厂商',
    prop: 'soleVendor'
  },
  {
    label: '大底类别',
    prop: 'soleMtl'
  },
  {
    label: '版师',
    prop: 'styleAbbr'
  },
  {
    label: '核料员',
    prop: 'mtlChecker'
  }
])

// 分页器
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(0)
const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}

// 获取表数据
const getTableList = debounce(async () => {
  let tableDataList = await service.post<any, any>('/quotation/getStyleResearch', {
    custom: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '客户')
      ?.selectValue,
    customStyle: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入客户型体'
    )?.inputValue,
    cut: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入冲刀'
    )?.inputValue,
    pageNum: currentPage.value,
    pageSize: pageSize.value,
    season: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '季度')
      ?.selectValue,
    shoeName: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入鞋名'
    )?.inputValue,
    style: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入型体'
    )?.inputValue,
    techPerson: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '制单员')
      ?.selectValue
  })
  tableData.value = tableDataList.list
  total.value = tableDataList.total
}, 500)
onMounted(() => {
  getTableList()
})
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList()
  }
)
// 获取下拉框数据
const getSelectList = async () => {
  return new Promise(async (resolve, reject) => {
    let { seasons, techPerson, customStyles } = (await service.get('/quotation/getStyleResearchCondition')) as any
    let techPer = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '制单员'
    ) as any
    let season = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '季度'
    ) as any
    let customStyle = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '客户'
    ) as any
    formList.value.forEach((item: any) => {
      if (item.type === 'select') {
        item.selectOptions = []
      }
    })
    // 插入制单员
    if (techPerson && techPer) {
      ;(techPerson as string[]).forEach((item: string, index) => {
        if (item === null) return
        techPer.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入制单员
    if (seasons && season) {
      ;(seasons as string[]).forEach((item: string, index) => {
        if (item === null) return
        season.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入制单员
    if (customStyles && customStyle) {
      ;(customStyles as string[]).forEach((item: string, index) => {
        if (item === null) return
        customStyle.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    resolve('')
  })
}
onMounted(() => {
  getSelectList()
})

const tableData2 = ref([])
const tableHeader2 = ref([
  {
    label: '序号',
    prop: 'typeNo'
  },
  {
    label: '楦头编号',
    prop: 'cutTool'
  },
  {
    label: '大底编号',
    prop: '"cutTool'
  },
  {
    label: '冲刀编号',
    prop: '"solePart'
  },
  {
    label: '中底编号',
    prop: 'midSole'
  },
  {
    label: '鞋垫编号',
    prop: 'inSole'
  },
  {
    label: '段',
    prop: 'itemName'
  },
  {
    label: '鞋码起',
    prop: 'size1'
  },
  {
    label: '鞋码止',
    prop: 'size2'
  }
])
const tableData3 = ref([])
const tableHeader3 = ref([
  {
    label: '鞋码',
    prop: 'sizeNo'
  },
  {
    label: '冲刀',
    prop: 'cutSize'
  },
  {
    label: '楦头',
    prop: 'lastSize'
  },
  {
    label: '大底',
    prop: 'soleSize'
  },
  {
    label: '中底',
    prop: 'midSoleSize'
  },
  {
    label: '鞋垫/脚床',
    prop: 'inSoleSize'
  }
])
const imgList = ref([])
const tableData4 = ref([])
const tableHeader4 = ref([
  {
    label: '序号',
    prop: 'seqNo'
  },
  {
    label: '颜色代号',
    prop: 'colorCode'
  },
  {
    label: '颜色名称',
    prop: 'styleColor'
  },
  {
    label: '颜色名称(英)',
    prop: 'engStyleColor'
  },
  {
    label: '颜色简称',
    prop: 'shortStyleColor'
  },
  {
    type: 'img',
    label: '图片',
    fixed: true,
    prop: 'photoPath',
    srcList: imgList
  }
])
// 点击表一给另三张表传数据
const isLoading2 = ref(false)
const currentRow = async (row: any) => {
  let { styleNo } = row
  isLoading2.value = true
  // 给表二传指令号
  let table2Data = await service.get<any, any>('/quotation/getStyleResearchDetail', {
    params: {
      styleNo
    }
  })
  tableData2.value = table2Data.styleTools
  tableData3.value = table2Data.styleCode
  tableData4.value =
    table2Data.styleColor.length !== 0
      ? table2Data.styleColor.map((item: any) => {
          item.seqNo = Number(item.seqNo).toFixed(2)
          return item
        })
      : []
  imgList.value = table2Data.styleColor.map((item: any) => {
    return item.photoPath
  })
  isLoading2.value = false
}
</script>

<style lang="less" scoped>
table {
  table-layout: auto !important;
}

:deep(.el-table__header) {
  width: 100% !important;
}

:deep(.el-table__body) {
  width: 100% !important;
}

.top {
  :deep(.el-input) {
    height: 25px;
    color: red;
    width: 80px !important;
  }

  :deep(.el-form-item__label) {
    width: 90px;
    justify-content: end;
    padding-right: 10px;
  }

  :deep(.right) {
    .el-form {
      flex-wrap: wrap;
      width: 290px;

      .el-form-item {
        justify-content: space-between;
        width: 60px;
        margin-top: 30px;
        margin-right: 20px !important;
      }
    }
  }
}

.main {
  :deep(.el-form-item:first-child) {
    width: 350px;

    .el-input__inner {
      width: 300px;
    }
  }

  :deep(.w-50) {
    width: 100px !important;
  }

  :deep(.el-form-item__content) {
    margin-right: 40px !important;
  }
}

// 表格内容居中
:deep(.el-table .cell.el-tooltip) {
  min-width: auto;
}
</style>
